package com.litchi.tutor.controller;

import com.litchi.tutor.common.base.ResponseVO;
import com.litchi.tutor.common.entity.User;
import com.litchi.tutor.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author XuRuiPeng
 * @date 2021/11/4 14:21
 */
@Slf4j
@RestController
@RequestMapping("/staff")
@Api("测试管理")
public class StaffController {

    @Autowired
    UserService userService;


    @RequestMapping(value = "/role/{userId}", method = RequestMethod.PUT)
    @ApiOperation("管理员修改角色，role（必填）传 1 表示修改为家长，2 表示修改为老师")
    public ResponseVO updateRoleByAdmin(@PathVariable Integer userId, @RequestBody User user) {
        userService.updateRoleByAdmin(userId, user);
        return ResponseVO.ok(null);
    }

    @RequestMapping(value = "/role/{userId}", method = RequestMethod.DELETE)
    @ApiOperation("删除用户角色（解绑）")
    public ResponseVO deleteRole(@PathVariable Integer userId) {
        userService.deleteRole(userId);
        return ResponseVO.ok(null);
    }
    @RequestMapping(value = "/user", method = RequestMethod.DELETE)
    @ApiOperation("删除用户（注销）")
    public ResponseVO deleteUser(@RequestParam Integer userId, HttpServletRequest request) {
        userService.deleteUser(userId,request);
        return ResponseVO.ok(null);
    }
}
